package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.SysMenuService;
import com.atguigu.spzx.model.dto.system.SysMenuDto;
import com.atguigu.spzx.model.entity.system.SysMenu;
import com.atguigu.spzx.model.entity.system.SysRole;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @author MikeCoder
 * @create 2023-12-0615:46
 * @description:
 * @verson:
 */
@RestController
@RequestMapping("admin/system/sysMenu")
@Tag(name = "菜单管理接口")
public class SysMenuController {

    @Autowired
    private SysMenuService sysMenuService;

    @Operation(summary = "展示菜单树")
    @GetMapping("/findMenuTree")
    public Result<List<SysMenu>> findMenuTree(){
        List<SysMenu> menusTree = sysMenuService.findMenuTree();
        return Result.build(menusTree, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "添加菜单")
    @PostMapping("/addMenu")
    public Result addMenu(@RequestBody SysMenu sysMenu){
        sysMenuService.addMenu(sysMenu);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "添加子菜单")
    @PostMapping("/addChildrenMenu")
    public Result addChildrenMenu(@RequestBody SysMenu sysMenu){
        sysMenuService.addChildrenMenu(sysMenu);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "得到父菜单标题")
    @GetMapping("/getParentTitle/{id}")
    public Result getParentTitle(@PathVariable Long id){
        String parentTitle = sysMenuService.getParentTitle(id);
        return Result.build(parentTitle,ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "修改菜单信息")
    @PutMapping("updateMenu")
    public Result updateMenu(@RequestBody SysMenuDto sysMenuDto){
        SysMenu sysMenu = sysMenuDto.getSysMenu();
        String parentTitle = sysMenuDto.getParentTitle();
        sysMenuService.updateMenu(sysMenu,parentTitle);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "删除菜单信息")
    @PostMapping("/removeSysMenu")
    public Result removeSysMenu(@RequestBody SysMenu sysMenu){
        sysMenuService.removeSysMenu(sysMenu);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

}
